package LOGIN;

import mapper.impl.AdmMapperImpl;
import mapper.impl.StudentMapperImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.spi.http.HttpContext;
import java.io.IOException;
@WebServlet("/add")
public class insert extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        StudentMapperImpl stuMapper = new StudentMapperImpl();
        if (req.getParameter("no")== null || req.getParameter("no") ==""){

            req.setAttribute("error","学号不能为空");
            req.getRequestDispatcher("/error(Test).jsp").forward(req,resp);
            return;
        }else if
//

         (req.getParameter("name") == null ||req.getParameter("name") == ""){
            req.setAttribute("error","姓名不能为空");
            req.getRequestDispatcher("/error(Test).jsp").forward(req,resp);
            return;
        }
         else if (req.getParameter("sex") == null || req.getParameter("sex") ==""){

            req.setAttribute("error","性别不能为空");
            req.getRequestDispatcher("/error(Test).jsp").forward(req,resp);
            return;
        }
       else if (req.getParameter("account") == null || req.getParameter("account") ==""){

            req.setAttribute("error","账号不能为空");
            req.getRequestDispatcher("/error(Test).jsp").forward(req,resp);
            return;
        }
        if (req.getParameter("phone") == null || req.getParameter("phone") ==""){

            req.setAttribute("error","电话不能为空");
            req.getRequestDispatcher("/error(Test).jsp").forward(req,resp);
            return;
        }
      else if ( req.getParameter("age") == null ||  req.getParameter("age") ==""){

            req.setAttribute("error","年龄不能为空");
            req.getRequestDispatcher("/error(Test).jsp").forward(req,resp);
            return;
        }else {
            stuMapper.addStu(req.getParameter("no"),req.getParameter("name"),req.getParameter("account"),req.getParameter("sex"),req.getParameter("phone"),req.getParameter("age"));
            req.setAttribute("error","添加成功");
            req.getRequestDispatcher("/error(Test).jsp").forward(req,resp);
        }
//
//        StudentMapperImpl stuinsert = stuMapper;
//        boolean addSt = stuinsert.addStu(S_No, name, account, sex, phone, age);
//        if (addSt==false){
//            req.setAttribute("error","您要存储的信息："+addSt+"已存在，请您重新输入");
//            req.getRequestDispatcher("/WEB-INF/error(Test).jsp").forward(req,resp);
//            return;
        }
    }
